#include <stdio.h>
#include <stdlib.h>
#define SIZE 1024
int main()
{
    char buf[SIZE];                             //缓冲区
    if (setvbuf(stdin, buf, _IONBF, SIZE) != 0) //将标准输入的缓冲类型设为无缓冲
    {
        printf("error!\n");
        exit(1);
    }
    printf("OK,set successful!\n");
    printf("stdin is ");                //打印缓冲区信息
    if (stdin->_flags & _IO_UNBUFFERED) //判断标准输入流对象的缓冲区类型
        printf("unbuffered\n");         //无缓存
    else if (stdin->_flags & _IO_LINE_BUF)
        printf("line-buffered\n"); //行缓存
    else
        printf("fullyj-buffered\n");                                         //全缓存
    printf("buffer size is %d\n", stdin->_IO_buf_end - stdin->_IO_buf_base); //打印缓冲区的大小

    printf("file discriptor is %d\n", fileno(stdin)); //标准输入流的文件描述符
    if (setvbuf(stdin, buf, _IOLBF, SIZE) != 0)
    {
        //将标准输入的缓冲类型设为全缓冲，缓存大小为1024
        printf("error!\n");
        exit(1);
    }
    printf("OK,change successful!\n");
    printf("stdin is ");
    if (stdin->_flags & _IO_UNBUFFERED) //判断标准输入流对象的缓冲区类型
        printf("unbuffered\n");         //无缓存
    else if (stdin->_flags & _IO_LINE_BUF)
        printf("line-buffered\n"); //行缓存
    else
        printf("fully-buffered\n");                                          //全缓存
    printf("buffer size is %d\n", stdin->_IO_buf_end - stdin->_IO_buf_base); //打印缓冲区的大小
    printf("file discriptor is %d\n\n", fileno(stdin));                      //标准输出流的文件描述符
    return 0;
}